var e = require;
var t = module;
var o = exports;
var ii, nn = this && this.__extends || (ii = function (t, e) {
    return (ii = Object.setPrototypeOf || {
        __proto__: []
    }
        instanceof Array &&
        function (t, e) {
            t.__proto__ = e
        } ||
        function (t, e) {
            for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o])
        })(t, e)
},
    function (t, e) {
        function o() {
            this.constructor = t
        }
        ii(t, e),
            t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o)
    }
),
    rr = this && this.__awaiter ||
        function (t, e, o, i) {
            return new (o || (o = Promise))(function (n, a) {
                function r(t) {
                    try {
                        l(i.next(t))
                    } catch (e) {
                        a(e)
                    }
                }
                function s(t) {
                    try {
                        l(i.
                            throw(t))
                    } catch (e) {
                        a(e)
                    }
                }
                function l(t) {
                    var e;
                    t.done ? n(t.value) : (e = t.value, e instanceof o ? e : new o(function (t) {
                        t(e)
                    })).then(r, s)
                }
                l((i = i.apply(t, e || [])).next())
            })
        };
var oo = (this && this.__decorate) ||
    function (e, t, a, n) {
        var i,
            o = arguments.length,
            s = o < 3 ? t : null === n ? (n = Object.getOwnPropertyDescriptor(t, a)) : n;
        if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) s = Reflect.decorate(e, t, a, n);
        else
            for (var r = e.length - 1; r >= 0; r--)
                (i = e[r]) && (s = (o < 3 ? i(s) : o > 3 ? i(t, a, s) : i(t, a)) || s);
        return o > 3 && s && Object.defineProperty(t, a, s), s;
    };
Object.defineProperty(o, "__esModule", { value: !0 });
var a = e("NotifyEventType"),
    n = e("GlobalParams"),
    i = e("AssetsManager"),
    r = e("AudioManager"),
    s = e("ModuleUI"),
    l = e("ArrayUtil"),
    _ = e("CommonHelper"),
    c = e("Game"),
    d = e("nameCfg"),
    h = e("RoleSoldierInfo"),
    u = e("sdkConfig"),
    p = e("AD"),
    m = e("role_node_item"),
    f = e("TipViewUI"),
    v = cc._decorator,
    g = v.ccclass,
    y = v.property,
    I = (function (e) {
        function t() {
            var t = (null !== e && e.apply(this, arguments)) || this;
            return (
                (t.my_power_label = null),
                (t.tare_times_label = null),
                (t.my_team_hero = null),
                (t.other_team_hero = null),
                (t.dare_power_view = null),
                (t.rand_power_name = []),
                (t.rand_power_one_list = [
                    [-20, -11],
                    [-10, -1],
                    [1, 5],
                    [6, 15],
                    [16, 30]
                ]),
                (t.random_get_equip = []),
                t
            );
        }
        return (
            nn(t, e),
            (t.prototype.initView = function () {
                e.prototype.initView.call(this), this.showVsUpbaseInfo();
            }),
            (t.prototype.addEvent = function () {
                this.attachEvent(a.default.SEND_PLAYER_CHOOSE_DARE_INDEX, this.showChooseDareInfo, this),
                    this.attachEvent(a.default.SEND_PLAYER_CHOOSE_DARE_PLAYER_INFO, this.darePlayerInfo, this);
            }),
            (t.prototype.OnClick = function (t) {
                var o = this;
                switch ((e.prototype.OnClick.call(this, t), t.node.name)) {
                    case "update_btn":
                        p.default.getInstance().showVideo(function (e) {
                            r.default.playGameBGM(), e == p.ResultEnum.Success && o.updateDareHeroInfo();
                        });
                        break;
                    case "ranking_btn":
                        this.uiManager.showPopup("DungeonRankingViewUI");
                        break;
                    case "team_btn":
                        this.uiManager.showPopup("DungeonModeChooseHero"), this.closeThisPopup();
                        break;
                    case "back_btn":
                        this.closeThisPopup();
                }
            }),
            (t.prototype.showVsUpbaseInfo = function () {
                var e = n.GlobalParams.DungeonModeHero.value;
                e.today != new Date().toLocaleDateString() &&
                    ((e.dare_times = 5),
                        (e.today = new Date().toLocaleDateString()),
                        this.updateDareHeroInfo(),
                        this.getRankingInfo(),
                        (n.GlobalParams.DungeonModeHero.value = e)),
                    e.update_dare && this.updateDareHeroInfo(),
                    (this.my_power_label.string = "" + e.power),
                    this.showHeroHeadInfo(this.my_team_hero, e.hero),
                    this.showHeroHeadInfo(this.other_team_hero, [-1, -1, -1]),
                    (this.tare_times_label.string = e.dare_times + "/5"),
                    this.showDareInfo();
            }),
            (t.prototype.updateDareHeroInfo = function () {
                var e = n.GlobalParams.DungeonModeHero.value;
                (this.rand_power_name = []),
                    this.rand_power_name.push(n.GlobalParams.PlayerInfo.value.name),
                    (e.dare_info = this.getPlayerInfo()),
                    (n.GlobalParams.DungeonModeHero.value = e),
                    this.showDareInfo(),
                    this.showHeroHeadInfo(this.other_team_hero, [-1, -1, -1]);
            }),
            (t.prototype.showHeroHeadInfo = function (e, t) {
                for (var o = 0; o < 3; o++)
                    if (-1 != t[o]) {
                        var a = "hero_" + h.default.Role_info[t[o]].id;
                        e.children[o].getComponent(cc.Sprite).spriteFrame = i.default
                            .getInstance()
                            .getGameHoreHeadFrame(a);
                    } else e.children[o].getComponent(cc.Sprite).spriteFrame = null;
            }),
            (t.prototype.showDareInfo = function () {
                for (var e = 0; e < 5; e++)
                    this.dare_power_view.children[e]
                        .getComponent(m.default)
                        .showRoleInfo(e, n.GlobalParams.DungeonModeHero.value.dare_info[e]);
            }),
            (t.prototype.showChooseDareInfo = function (e, t) {
                var o = n.GlobalParams.DungeonModeHero.value.dare_info[t].hero;
                this.showHeroHeadInfo(this.other_team_hero, o);
            }),
            (t.prototype.darePlayerInfo = function (e, t) {
                var o = this,
                    a = n.GlobalParams.PlayerInfo.value,
                    i = n.GlobalParams.DungeonModeHero.value;
                if (-1 == i.hero.indexOf(-1)) {
                    if (i.dare_times <= 0)
                        this.uiManager.showPopup("TipViewUI", function (e) {
                            e.getComponent(f.default).showTipInfo(
                                "每日挑战次数为0\n是否观看视频获得次数",
                                !0,
                                function () {
                                    (i.dare_times = 5),
                                        (n.GlobalParams.DungeonModeHero.value = i),
                                        o.showVsUpbaseInfo();
                                }
                            );
                        });
                    else {
                        i.dare_times--, (n.GlobalParams.DarePlayerInfo = null);
                        for (var r = [], s = 0; s < 2; s++) {
                            var _ = {
                                name: 0 == s ? a.name : t.name,
                                power: 0 == s ? i.power : t.power,
                                head: 0 == s ? a.head : t.head,
                                schedule: 0
                            };
                            r.push(_);
                        }
                        (n.GlobalParams.DarePlayerInfo = r),
                            (this.random_get_equip = this.random_get_equip.concat(c.default.equip_ball_list)),
                            (this.random_get_equip = l.default.fisherYatesShuffle(this.random_get_equip));
                        var d = this.getAiEquip();
                        for (n.GlobalParams.MatchGamePlayer = [], s = 0; s < 6; s++)
                            (_ = {
                                name: s < 3 ? a.name : t.name,
                                head: s < 3 ? a.head : t.head,
                                role_id: s < 3 ? i.hero[s] : t.hero[s - 3],
                                player_skill: [1, 2],
                                dower_info: [0, 0],
                                level: 10,
                                exp_num: 0,
                                kill_info: [0, 0, 0],
                                skill_info: [5, 5],
                                equip_info: s < 3 ? [0, 0, 0] : d.splice(0, 3),
                                coin: 0
                            }),
                                n.GlobalParams.MatchGamePlayer.push(_);
                        cc.log(n.GlobalParams.MatchGamePlayer), this.uiManager.showPopup("LoadingViewUI");
                    }
                } else
                    this.uiManager.showPopup("TipViewUI", function (e) {
                        e.getComponent(f.default).showTipInfo("请先配置3名出战的英雄");
                    });
            }),
            (t.prototype.getPlayerInfo = function () {
                var e = [],
                    t = n.GlobalParams.DungeonModeHero.value.power;
                t = 0 == t ? 20 : t;
                for (var o = 0; o < 5; o++) {
                    var a,
                        i = {
                            name: "",
                            power: 0,
                            head:
                                u.default.platform != u.EPlatform.NET_4399
                                    ? _.default.getRandomInt(1, 19)
                                    : _.default.getRandomInt(1, 9),
                            hero: [-1, -1, -1]
                        },
                        r = "";
                    do {
                        r =
                            u.default.platform != u.EPlatform.NET_4399
                                ? d.default.nameList[_.default.getRandomInt(0, d.default.nameList.length - 26)]
                                : "4399玩家" + _.default.getRandomInt(1e3, 9999);
                    } while (-1 != this.rand_power_name.indexOf(r));
                    (i.name = r),
                        (a =
                            t + _.default.getRandomInt(this.rand_power_one_list[o][0], this.rand_power_one_list[o][1])),
                        (i.power = a);
                    for (var s = [], l = 0; l < 3; l++) {
                        var c = 0;
                        do {
                            c =
                                n.GlobalParams.GameHeroIndex[
                                _.default.getRandomInt(0, n.GlobalParams.GameHeroIndex.length - 1)
                                ];
                        } while (-1 != s.indexOf(c));
                        s.push(c);
                    }
                    (i.hero = s), e.push(i);
                }
                return e;
            }),
            (t.prototype.getRankingInfo = function () {
                var e = n.GlobalParams.DungeonModeHero.value,
                    t = 0;
                t = e.power_info.length > 0 ? e.power_info[0].power : _.default.getRandomInt(3e3, 6e3);
                for (var o = [], a = [], i = 0; i < 10; i++) {
                    var r = {
                        name: "",
                        power: 0,
                        head:
                            u.default.platform != u.EPlatform.NET_4399
                                ? _.default.getRandomInt(1, 19)
                                : _.default.getRandomInt(1, 9),
                        hero: [-1, -1, -1],
                        level: _.default.getRandomInt(15, 28)
                    },
                        s = "";
                    do {
                        s =
                            u.default.platform != u.EPlatform.NET_4399
                                ? d.default.nameList[
                                _.default.getRandomInt(
                                    d.default.nameList.length - 25,
                                    d.default.nameList.length - 1
                                )
                                ]
                                : "4399玩家" + _.default.getRandomInt(1e3, 9999);
                    } while (-1 != o.indexOf(s));
                    (r.name = s), o.push(s), (t -= _.default.getRandomInt(10, 60)), (r.power = t);
                    for (var l = [], c = 0; c < 3; c++) {
                        var h = 0;
                        do {
                            h =
                                n.GlobalParams.GameHeroIndex[
                                _.default.getRandomInt(0, n.GlobalParams.GameHeroIndex.length - 1)
                                ];
                        } while (-1 != l.indexOf(h));
                        l.push(h);
                    }
                    (r.hero = l), a.push(r);
                }
                e.power_info = a;
            }),
            (t.prototype.getAiEquip = function () {
                for (var e = n.GlobalParams.DarePlayerInfo[1].power, t = [], o = 0; o < 9; o++)
                    o < this.getEquipNum(e) ? t.push(this.getRandomEquip()) : t.push(0);
                return l.default.fisherYatesShuffle(t);
            }),
            (t.prototype.getRandomEquip = function () {
                var e = _.default.getRandomInt(0, this.random_get_equip.length - 1),
                    t = this.random_get_equip[e];
                return this.random_get_equip.splice(e, 1), t;
            }),
            (t.prototype.getEquipNum = function (e) {
                return e < 20
                    ? 0
                    : e < 50
                        ? 1
                        : e < 100
                            ? 2
                            : e < 200
                                ? 3
                                : e < 1e3
                                    ? 4
                                    : e < 3e3
                                        ? 5
                                        : e < 1e4
                                            ? 6
                                            : e < 3e4
                                                ? 7
                                                : e < 5e4
                                                    ? 8
                                                    : 9;
            }),
            oo([y(cc.Label)], t.prototype, "my_power_label", void 0),
            oo([y(cc.Label)], t.prototype, "tare_times_label", void 0),
            oo([y(cc.Node)], t.prototype, "my_team_hero", void 0),
            oo([y(cc.Node)], t.prototype, "other_team_hero", void 0),
            oo([y(cc.Node)], t.prototype, "dare_power_view", void 0),
            oo([g], t)
        );
    })(s.default);
o.default = I;
